package com.wlhse.controller;

import com.wlhse.dto.inDto.ProblemImportInDto1;
import com.wlhse.entity.TaskObjectPojo;
import com.wlhse.service.ProblemImportService1;
import com.wlhse.service.TaskObjectService;
import com.wlhse.util.GetCurrentUserIdUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController("/TaskObjectController")
@RequestMapping("/api/v1")
//任务目标
public class TaskObjectController {

    @Resource
    private TaskObjectService taskObjectService;

    @Resource
    private ProblemImportService1 problemImportService1;

    @Resource
    private GetCurrentUserIdUtil getCurrentUserIdUtil;

    @RequestMapping(value = "/task_object", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    public String getTaskObjects(@RequestParam(value = "taskObjectName", required = false, defaultValue = "") String taskObjectName, @ModelAttribute TaskObjectPojo taskObjectPojo) {
        return taskObjectService.getTaskObjectByCondition(taskObjectName, taskObjectPojo);
    }

    @RequestMapping(value = "/task_object/{id}", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    public String getTaskObject(@PathVariable("id") String id) {
        return taskObjectService.getTaskObject(id);
    }

    @RequestMapping(value = "/task_object", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public String addTaskObject(@RequestBody(required = false) TaskObjectPojo taskObjectPojo) {
        return taskObjectService.addTaskObject(taskObjectPojo);
    }

    @RequestMapping(value = "/task_object/id", method = RequestMethod.PUT, produces = "application/json; charset=utf-8")
    public String updateTaskObject(@RequestBody(required = false) TaskObjectPojo taskObjectPojo) {
        return taskObjectService.updateTaskObject(taskObjectPojo);
    }

    @RequestMapping(value = "/task_object/{id}", method = RequestMethod.DELETE, produces = "application/json; charset=utf-8")
    public String deleteTaskObject(@PathVariable("id") String id) {
        return taskObjectService.removeTaskObject(id);
    }

    @RequestMapping(value = "/tasks/name", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    public String returnTaskName(@ModelAttribute ProblemImportInDto1 problemImportInDto1, HttpServletRequest request) {
        return problemImportService1.listTaskName(problemImportInDto1, getCurrentUserIdUtil.getUserId(request));
    }

}
